<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>压平</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }


        .box {
            display: grid;
            grid-template-columns: 1fr 1fr;
            margin-bottom: 10px;
            grid-row-gap: 5px;
            align-items: center;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="box">
            <label for="arrow">是否显示箭头</label><input type="checkbox" id="arrow" onchange="showArrow()" />

            <label for="lineWidth">轮廓线宽度</label><input type="number" id="edgetWidth" onchange="setEdgetWidth()"
                value="2">
            <label for="width">宽度</label><input type="number" id="width" onchange="setWidth()" value="200">
            <label for="height">高度</label><input type="number" id="height" onchange="setHeight()" value="200">
        </div>
        <button onclick="start()">开始绘制</button>
        <button onclick="deleteClippingObj()">删除</button>
    </div>
    <script>

        /** -----------------------------------------地球创建----------------------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']
        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;
        // 监听视口状态
        objm.viewerCreatedEvent.don((viewer) => {
            viewer.flyIn(
                [108.96299571058906, 34.21678028533886, 646.936464988799], [307.19168576953393, -31.653922742502324, 0.0005275461534735532], 3
            )
        });
        // 创建Cesium视口
        const viewer = objm.createCesiumViewer(document.getElementById("app"));


        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 16,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        //添加3DTileset
        const eS3DTileset = objm.createSceneObjectFromJson({
            "id": "c2c8311e-6e50-47a2-b764-1c82f2d0e256",
            "type": "ES3DTileset",
            "name": "ES3DTileset",
            "allowPicking": true,
            "url": "https://www.earthsdk.com/assets/tileset/osgb_dayanta/tileset.json"
        })


        let clippingObj = null;
        const start = () => {
            if (clippingObj) {
                deleteClippingObj()
            }
            const clippingObject = objm.createSceneObject('ESClippingPlane')
            clippingObject.targetID = eS3DTileset.id;
            clippingObject.height = Number(document.getElementById('height').value)
            clippingObject.width = Number(document.getElementById('width').value)
            clippingObject.edgetWidth = Number(document.getElementById('edgetWidth').value)
            clippingObject.showArrow = document.getElementById('arrow').checked
            clippingObject.editing = true;
            clippingObj = clippingObject;
        }
        const deleteClippingObj = () => {
            if (clippingObj) {
                objm.destroySceneObject(clippingObj)
                clippingObj = null
            }
        }
    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>